using System;
using System.Collections.Generic;
using System.Text;

namespace Decav.Diagnostics
{
    /// <summary>
    /// Holds helper methods to assist in diagnostics.
    /// </summary>
    public static class DecavDiagnostics
    {
        /// <summary>
        /// Gets the details about an exception as a string.
        /// </summary>
        /// <param name="ex">The exception to get details for.</param>
        /// <returns>The string regarding the exception.</returns>
        public static string GetExceptionDetails(Exception ex)
        {
            if (ex == null)
                throw new ArgumentNullException("ex");

            StringBuilder builder = new StringBuilder();
            builder.AppendLine("=======ENVIRONMENT=======");


            builder.AppendLine();
            builder.AppendLine();

            Exception current = ex;
            do
            {
                builder.AppendLine("=======EXCEPTION========");
                builder.AppendFormat("TYPE:      {0}\r\n", current.GetType().Name);
                builder.AppendFormat("MESSAGE:   {0}\r\n", current.Message);
                builder.AppendLine("-------------");
                builder.AppendLine(current.StackTrace);

                builder.AppendLine();
                builder.AppendLine();
            }
            while ((current = current.InnerException) != null);

            return builder.ToString();
        }
    }
}
